package com.example.boot.rabbitmq.producer.demo.config.direct;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;

/**
 * direct配置
 * @author root
 * @date 2021-03-06 14:21
 */
//@Configuration
@RequiredArgsConstructor
public class RabbitDirectConfig {


    private final RabbitDirectProperties rabbitDirectProperties;

    /**
     * 配置diorect类型交换器
     * @return 交换器
     */
    @Bean
    public DirectExchange directExchangeNew(){
        return new DirectExchange(rabbitDirectProperties.getDirectExchange());
    }

    /**
     * 声明一个持久化的队列
     * @return 声明队列
     */
    @Bean
    public Queue directQueue() {
//        return new Queue(rabbitDirectProperties.getDirectQueue());
        return QueueBuilder.durable(rabbitDirectProperties.getDirectQueue()).build();
    }

    /**
     * 队列交换机绑定
     * @param directExchangeNew 交换器
     * @param directQueue 队列
     * @return 绑定信息
     */
    @Bean
    public Binding directBindingNew(DirectExchange directExchangeNew, Queue directQueue) {
        return BindingBuilder.bind(directQueue)
                .to(directExchangeNew)
                .with(rabbitDirectProperties.getDirectKey());
    }



}
